package springcloud.test.product.config;

import com.netflix.discovery.endpoint.EndpointUtils;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerListFilter;
import org.springframework.cloud.netflix.ribbon.ZonePreferenceServerListFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//全局自定义ServerListFilter 和 负载均衡策略
@Configuration
public class GlobalConfiguration {
    @Bean(name = "ribbonServerListFilter")
    public ServerListFilter<Server> serverListFilter() {
        ZonePreferenceServerListFilter filter = new ZonePreferenceServerListFilter();
        filter.setZone(EndpointUtils.DEFAULT_ZONE);

        return filter;
    }

    @Bean
    public IRule rule() {
        return new RandomRule();
    }
}
